//logs.js
const util = require('../../utils/util.js')
import request from "../../utils/request";
var api = require("../../utils/api");
var app = getApp()
Page({
  data: {
    page: 1,// 第几页
    resultContent: '',
    loading: false,
    access_token: '354c3be6ced8dea9d0d9296a0add28fb',
    cellData: [],
    listType: 0,
    stateArr: [{
        name: '',
        className: '',
        textClass: ''
      }, {
        name: '待处理',
        className: 'back-blue',
        textClass: 'blue'
      },
      {
        name: '待处理',
        className: 'back-green',
        textClass: 'green'
      },
      {
        name: '已处理',
        className: 'back-yellow',
        textClass: 'yellow'
      },
      {
        name: '处理中',
        className: 'back-green',
        textClass: 'green'
      }, {
        name: '已处理',
        className: 'back-red',
        textClass: 'red'
      }, {
        name: '已奖励',
        className: 'back-red',
        textClass: 'red'
      }
    ],
    noData: false
  },

  onLoad(option) {
    var listType = option.listType
    this.setData({
      listType: listType
    }),
    this.fetchData(this.data.listType)
  },
  onShow() {
    // this.fetchData(this.data.listType)
  },
  onCell(e){
    var id = e.currentTarget.dataset.rowid
    var listtype = e.currentTarget.dataset.listtype
    if (app.globalData.isBoss){
      wx.navigateTo({
        url: "/pages/details/details?rowId=" + id + "&&listType=" + listtype,
      })
    }else{
      wx.navigateTo({
        url: "/pages/checkDetails/checkDetails?rowId=" + id + "&&listType=" + listtype,
      })
    }
  },
  // 下拉事件
  onPullDownRefresh(){
    // var curPage = this.data.page
    // debugger
    // // 待测试
    // if(this.data.page > 1){
    //   this.setData({
    //     page: curPage - 1,
    //     // cellData: this.data.cellData.clice(,this.data.cellData.length-1)
    //   })
    // }
    this.setData({
      page: 1,
      // cellData: this.data.cellData.clice(,this.data.cellData.length-1)
    })
    this.fetchData(this.data.listType)
  },
  //上啦触底
  onReachBottom: function () {
    let page = this.data.page
      this.setData({
        page: page + 1,
      }) 
    this.fetchData(this.data.listType)
  },
  fetchData(listType) {
    var url = api.SecretSlist
    var self = this
    var params = {
      list_rows: 10,
      page: this.data.page,
      check_status: listType
    }
    request(url, params, "POST").then(res => {
      if (res.code == 0) {
        if (res.data.data.length <= 0){
          wx:wx.showToast({
            title: '无更多数据',
            icon: 'none',
          })
        }
        var result = []
        if(this.data.page >1){
          result = self.data.cellData.concat(res.data.data);
        }else{
          result = res.data.data
        }
        if (this.data.page > 1 && res.data.data.length <= 0) {
          this.setData({
            page: this.data.page - 1
          })
        }
        result.forEach(item=>{
          item.content = util.escape2Html(item.content)  
        })
        this.setData({
          cellData: result
        })
      }
    })
  }
})